package com.wn.class30.cotroller.houtai;

import com.wn.class30.entity.AdminUser;
import com.wn.class30.entity.MyorderShare;
import com.wn.class30.entity.PayOrder;
import com.wn.class30.service.MyorderShareService;
import com.wn.class30.service.PayorderShareService;
import com.wn.class30.tools.Page;
import com.wn.class30.tools.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author
 * @since 2020/4/18 9:48
 */
@RestController
@Slf4j
@RequestMapping("/houtai/page/finance/businesspay/")
public class PayorderShareController {
    private Integer abusinessId=0;
    private HashMap<Integer,Integer> maps =new HashMap<>();
    @Resource
    private PayorderShareService payorderShareService;
    //查询所有门店消费记录
    @RequestMapping("list")
    public Result selectPayorderShareDetail(Integer page,Integer limit,String businessId,String isSettlement,String startDate,String endDate,String businessName) throws Exception {
        Subject subject = SecurityUtils.getSubject();
        AdminUser adminUser = (AdminUser) subject.getPrincipal();
        if(adminUser.getBusinessId()!=0){
            businessId=adminUser.getBusinessId()+"";
        }
        Map<String,String> map = new HashMap<>();
        map.put("page",String.valueOf((page-1)*limit));
        map.put("limit",String.valueOf(limit));
        map.put("businessId",businessId);
        map.put("businessName",businessName);
        map.put("isSettlement",isSettlement);
        map.put("startDate",startDate);
        map.put("endDate",endDate);
        List<PayOrder> payorderShareList = payorderShareService.selectPayorderShares(map);
        Page page1 = new Page();
        long dataCount = payorderShareService.count(map);
        int pageCount = (int)(dataCount%limit==0?dataCount/limit:dataCount/limit+1);
        page1.setTotalSize(dataCount);
        page1.setPageSize(limit);
        page1.setCurrentPage(page);
        page1.setTotalPage(pageCount);
        return  new Result("0","success",page1,payorderShareList);
    }
    //byId查询门店消费记录
    @RequestMapping("qureyBusinessPayById")
    public Result selectProfitByBusinessId(Integer businessId) throws Exception {
        abusinessId = businessId;
        maps.put(abusinessId,abusinessId);
        return new Result("200","success",null,null);
    }
    //管理员查询某门店消费记录（table的url）
    @RequestMapping("queryForAdmin")
    public Result selectQueryForAdmin(Integer page,Integer limit,String isSettlement,String startDate,String endDate,String businessName) throws Exception {
        Integer id = maps.get(abusinessId);
        Result res = selectPayorderShareDetail(page,limit,id+"",isSettlement,startDate,endDate,businessName);
        List<PayOrder> li = (List<PayOrder>) res.getLi();

        Page page1 = new Page();
        page1.setTotalSize(((Page)res.getObj()).getTotalSize());
        return new Result("0","success",page1,li);
    }

}
